
******SUM STATS AND BALANCE TESTS********

set more off
clear all 
clear matrix
capture log close

adopath + "$main/DoFiles"																		


local seed = 999
local reps = 5000

//--> BASELINE SURVEY AND MIS DATA

		use  "$data/baseline_fa_vars.dta", replace
		
//--> FA TREATMENT STATUS AND FU		

		sort fw_code
		merge fw_code using "$data/FWHR.dta"
		drop _m

		
		
		g bonus_status = 0 if treat==0
		replace bonus_status = 1 if treat_credit ==1
		replace bonus_status = 2 if treat_sm ==1
		
		
		//--> CONVERT NOT FIRST JOB TO FIRST JOB
		
			replace nfirst_job = 1 - nfirst_job
			
		
		
//--> OUTPUT: TABLE 1	
	*********************************************************************************************************************************************************
	
		putexcel set "$output/table1", replace
			putexcel A1 = "var name"
			putexcel B1 = "no bonus"
			putexcel C1 = "credit bonus"
			putexcel D1 = "social bonus"
		
		local count = 2
			local var_shortlist age female education work_month nfirst_job weighted_num_co_alive soc_help_credit volunteer_before_nrsp job_like_help weighted_num_active_loan inv_ratio_miss_pay_20 inv_ratio_miss_pay_month
			foreach v in `var_shortlist' {
				mean `v', over(bonus)
				putexcel A`count' = "`v'"
				putexcel B`count' = matrix(e(b))
				local count = `count' + 1
				}
				putexcel A`count' = "No. of FAs"
				putexcel B`count' = matrix(e(_N))
				
	*********************************************************************************************************************************************************


//--> OUTPUT: ONLINE APPENDIX TABLE D.1 (BALANCE TEST, FULL SAMPLE)
	*********************************************************************************************************************************************************
			
		local demo_var age female marital_status head_hh education consumption_hh
		local emp_var work_month nfirst_job work_vb weighted_num_co_alive
		local pref_var still_work_nrsp_2years overtime_perday credit_bonus soc_help_credit volunteer_before_nrsp job_like_help 
		local outcome_var weighted_num_active_loan inv_ratio_miss_pay_20 weighted_num_new_loan weighted_amount_issue inv_ratio_miss_pay_month wmiss_pay_maturity_month

		local var_longlist `demo_var' `emp_var' `pref_var' `outcome_var'
		
		
		//--> COLUMNS 1-3: MEANS BY TREATMENT STATUS
			*****************************************
		
				putexcel set "$output/tableD_1 (col1-3)", replace
					putexcel A1 = "var name"
					putexcel B1 = "no bonus"
					putexcel C1 = "credit bonus"
					putexcel D1 = "social bonus"
				
				local count = 2
				foreach v in `var_longlist' {
					mean `v', over (bonus_status)
						putexcel A`count' = "`v'"
						putexcel B`count' = matrix(e(b))
					local count = `count' + 1
					}
					putexcel A`count' = "No. of FAs"
					putexcel B`count' = matrix(e(_N))
		


		//--> COLUMNS 4-6: RANDOMIZATION INFERENCE BASED P VALUES
			****************************************		
				
				g x1 = treat_credit + treat_sm
				log using "$output/tableD_1 (col4-6)", replace	
			
						
				//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL		
								

						foreach v in `var_longlist' {
							randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
							}	
				
				//--> CREDIT VS. SOCIAL

						foreach v in `var_longlist' {
							randcmd((treat_credit) reg `v' treat_credit x1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
							}	
		
			
				//--> WESTFALL YOUNG OMIBUS TEST
	
					#delimit ;
						randcmd ((treat_credit treat_sm) reg age treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg female treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg marital_status treat_credit treat_sm, cluster(fu_feb05))
						((treat_credit treat_sm) reg head_hh treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg education treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg consumption_hh treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg work_month treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg nfirst_job treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg work_vb treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg weighted_num_co_alive treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg still_work_nrsp_2years treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg overtime_perday treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg credit_bonus treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg soc_help_credit treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg volunteer_before_nrsp treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg job_like_help treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg weighted_num_active_loan treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg inv_ratio_miss_pay_20 treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg weighted_num_new_loan treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg weighted_amount_issue treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg inv_ratio_miss_pay_month treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg wmiss_pay_maturity_month treat_credit treat_sm, cluster(fu_feb05))
						((treat_sm) reg age treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg female treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg marital_status treat_sm if treat==1, cluster(fu_feb05))
						((treat_sm) reg head_hh treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg education treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg consumption_hh treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg work_month treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg nfirst_job treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg work_vb treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg weighted_num_co_alive treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg still_work_nrsp_2years treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg overtime_perday treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg credit_bonus treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg soc_help_credit treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg volunteer_before_nrsp treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg job_like_help treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg weighted_num_active_loan treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg inv_ratio_miss_pay_20 treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg weighted_num_new_loan treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg weighted_amount_issue treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg inv_ratio_miss_pay_month treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg wmiss_pay_maturity_month treat_sm if treat==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed'); 
				
					#delimit cr
					
		log close			
		
		
				/*//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES (FOR ROBUSTNESS)
					****************************************
			
				//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
								
						foreach x in `var_longlist'{
							cgmwildboot `x' treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
							}
				
				//--> CREDIT VS. SOCIAL
				
						g x1 = treat_credit + treat_sm
						g test1 = treat_credit  //RELEVANT VAR FOR F TEST
			
						foreach x in `var_longlist'{
							cgmwildboot `x' test1 x1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
							}
							*/
	*********************************************************************************************************************************************************

	
//--> OUTPUT: ONLINE APPENDIX TABLE D.3 (BALANCE TEST, VERIFIED MPRS RESTRICTED SAMPLE)
	*********************************************************************************************************************************************************

		
		//--> KEEP FOLLOWUP SAMPLE ONLY
		
				preserve
				sort fw_code
				merge fw_code using "$data/social_fa_vars.dta"
				keep if _m==3
				drop _m		
		
		local demo_var age female marital_status head_hh education consumption_hh
		local emp_var work_month nfirst_job work_vb weighted_num_co_alive
		local pref_var still_work_nrsp_2years overtime_perday credit_bonus soc_help_credit volunteer_before_nrsp job_like_help 
		local outcome_var weighted_num_active_loan inv_ratio_miss_pay_20 weighted_num_new_loan weighted_amount_issue inv_ratio_miss_pay_month wmiss_pay_maturity_month

		local var_longlist `demo_var' `emp_var' `pref_var' `outcome_var'
		
		
		//--> COLUMNS 1-3: MEANS BY TREATMENT STATUS
			*****************************************
		
				putexcel set "$output/tableD_3 (col1-3)", replace
					putexcel A1 = "var name"
					putexcel B1 = "no bonus"
					putexcel C1 = "credit bonus"
					putexcel D1 = "social bonus"
				
				local count = 2
				foreach v in `var_longlist' {
					mean `v', over (bonus_status)
						putexcel A`count' = "`v'"
						putexcel B`count' = matrix(e(b))
					local count = `count' + 1
					}
					
					putexcel A`count' = "No. of FAs"
					putexcel B`count' = matrix(e(_N))
		


		//--> COLUMNS 4-6: RANDOMIZATION INFERENCE BASED P VALUES
			****************************************		
				
				log using "$output/tableD_3 (col4-6)", replace	
			
						
				//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL		

						foreach v in `var_longlist' {
							randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
							}	
				
				//--> CREDIT VS. SOCIAL

						foreach v in `var_longlist' {
							randcmd((treat_credit) reg `v' treat_credit x1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
							}	
		
			
				//--> WESTFALL YOUNG OMIBUS TEST
	
					#delimit ;
						randcmd ((treat_credit treat_sm) reg age treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg female treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg marital_status treat_credit treat_sm, cluster(fu_feb05))
						((treat_credit treat_sm) reg head_hh treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg education treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg consumption_hh treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg work_month treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg nfirst_job treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg work_vb treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg weighted_num_co_alive treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg still_work_nrsp_2years treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg overtime_perday treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg credit_bonus treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg soc_help_credit treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg volunteer_before_nrsp treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg job_like_help treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg weighted_num_active_loan treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg inv_ratio_miss_pay_20 treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg weighted_num_new_loan treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg weighted_amount_issue treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg inv_ratio_miss_pay_month treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg wmiss_pay_maturity_month treat_credit treat_sm, cluster(fu_feb05))
						((treat_sm) reg age treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg female treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg marital_status treat_sm if treat==1, cluster(fu_feb05))
						((treat_sm) reg head_hh treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg education treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg consumption_hh treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg work_month treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg nfirst_job treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg work_vb treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg weighted_num_co_alive treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg still_work_nrsp_2years treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg overtime_perday treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg credit_bonus treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg soc_help_credit treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg volunteer_before_nrsp treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg job_like_help treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg weighted_num_active_loan treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg inv_ratio_miss_pay_20 treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg weighted_num_new_loan treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg weighted_amount_issue treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg inv_ratio_miss_pay_month treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg wmiss_pay_maturity_month treat_sm if treat==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed'); 
				
					#delimit cr
				
				restore	
		log close			
		
	*********************************************************************************************************************************************************
	
		

			
//--> OUTPUT: ONLINE APPENDIX TABLE D.4 (BAANCE TEST, FOLLOWUP SURVEY RESTRICTED SAMPLE)
	*********************************************************************************************************************************************************
	
	
		//--> SELECTION IN FOLLOWUP SURVEY
			
				preserve
				use "$data/fASVY.dta", clear
				g endline= 1 if fname_thing_likemost_nrsp!=.
				keep fw_code endline
				sort fw_code
				tempfile temp_endline
				save `temp_endline'
				restore
				
				sort fw_code
				merge fw_code using `temp_endline'
				drop _m
		
		
		//--> KEEP FOLLOWUP SAMPLE ONLY
		
				preserve
				keep if endline==1
				
		
		local demo_var age female marital_status head_hh education consumption_hh
		local emp_var work_month nfirst_job work_vb weighted_num_co_alive
		local pref_var still_work_nrsp_2years overtime_perday credit_bonus soc_help_credit volunteer_before_nrsp job_like_help 
		local outcome_var weighted_num_active_loan inv_ratio_miss_pay_20 weighted_num_new_loan weighted_amount_issue inv_ratio_miss_pay_month wmiss_pay_maturity_month

		local var_longlist `demo_var' `emp_var' `pref_var' `outcome_var'
		
		
		//--> COLUMNS 1-3: MEANS BY TREATMENT STATUS
			*****************************************
		
				putexcel set "$output/tableD_4 (col1-3)", replace
					putexcel A1 = "var name"
					putexcel B1 = "no bonus"
					putexcel C1 = "credit bonus"
					putexcel D1 = "social bonus"
				
				local count = 2
				foreach v in `var_longlist' {
					mean `v', over (bonus_status)
						putexcel A`count' = "`v'"
						putexcel B`count' = matrix(e(b))
					local count = `count' + 1
					}
					
					putexcel A`count' = "No. of FAs"
					putexcel B`count' = matrix(e(_N))
		


		//--> COLUMNS 4-6: RANDOMIZATION INFERENCE BASED P VALUES
			****************************************		
				
				log using "$output/tableD_4 (col4-6)", replace	
			
						
				//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL		

						foreach v in `var_longlist' {
							randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
							}	
				
				//--> CREDIT VS. SOCIAL

						foreach v in `var_longlist' {
							randcmd((treat_credit) reg `v' treat_credit x1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
							}	
		
			
				//--> WESTFALL YOUNG OMIBUS TEST
	
					#delimit ;
						randcmd ((treat_credit treat_sm) reg age treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg female treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg marital_status treat_credit treat_sm, cluster(fu_feb05))
						((treat_credit treat_sm) reg head_hh treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg education treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg consumption_hh treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg work_month treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg nfirst_job treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg work_vb treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg weighted_num_co_alive treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg still_work_nrsp_2years treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg overtime_perday treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg credit_bonus treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg soc_help_credit treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg volunteer_before_nrsp treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg job_like_help treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg weighted_num_active_loan treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg inv_ratio_miss_pay_20 treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg weighted_num_new_loan treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg weighted_amount_issue treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg inv_ratio_miss_pay_month treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg wmiss_pay_maturity_month treat_credit treat_sm, cluster(fu_feb05))
						((treat_sm) reg age treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg female treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg marital_status treat_sm if treat==1, cluster(fu_feb05))
						((treat_sm) reg head_hh treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg education treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg consumption_hh treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg work_month treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg nfirst_job treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg work_vb treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg weighted_num_co_alive treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg still_work_nrsp_2years treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg overtime_perday treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg credit_bonus treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg soc_help_credit treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg volunteer_before_nrsp treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg job_like_help treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg weighted_num_active_loan treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg inv_ratio_miss_pay_20 treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg weighted_num_new_loan treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg weighted_amount_issue treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg inv_ratio_miss_pay_month treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg wmiss_pay_maturity_month treat_sm if treat==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed'); 
				
					#delimit cr
				
				restore	
		log close			
		
	*********************************************************************************************************************************************************

	

//--> OUTPUT: ONLINE APPENDIX TABLE D.5 (BAANCE TEST, CRO EVAL RESTRICTED SAMPLE)
	*********************************************************************************************************************************************************
	
	
		//--> SELECTION IN FOLLOWUP SURVEY
			
				preserve
				use "$data/eval_fa_vars.dta", clear
				keep fw_code eval_cro
				sort fw_code
				tempfile temp_eval_cro
				save `temp_eval_cro'
				restore
				
				sort fw_code
				merge fw_code using `temp_eval_cro'
				drop _m
		
		
		//--> KEEP FOLLOWUP SAMPLE ONLY
		
				preserve
				keep if eval_cro==1
				
		
		local demo_var age female marital_status head_hh education consumption_hh
		local emp_var work_month nfirst_job work_vb weighted_num_co_alive
		local pref_var still_work_nrsp_2years overtime_perday credit_bonus soc_help_credit volunteer_before_nrsp job_like_help 
		local outcome_var weighted_num_active_loan inv_ratio_miss_pay_20 weighted_num_new_loan weighted_amount_issue inv_ratio_miss_pay_month wmiss_pay_maturity_month

		local var_longlist `demo_var' `emp_var' `pref_var' `outcome_var'
		
		
		//--> COLUMNS 1-3: MEANS BY TREATMENT STATUS
			*****************************************
		
				putexcel set "$output/tableD_5 (col1-3)", replace
					putexcel A1 = "var name"
					putexcel B1 = "no bonus"
					putexcel C1 = "credit bonus"
					putexcel D1 = "social bonus"
				
				local count = 2
				foreach v in `var_longlist' {
					mean `v', over (bonus_status)
						putexcel A`count' = "`v'"
						putexcel B`count' = matrix(e(b))
					local count = `count' + 1
					}
					
					putexcel A`count' = "No. of FAs"
					putexcel B`count' = matrix(e(_N))
		


		//--> COLUMNS 4-6: RANDOMIZATION INFERENCE BASED P VALUES
			****************************************		
				
				log using "$output/tableD_5 (col4-6)", replace	
			
						
				//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL		

						foreach v in `var_longlist' {
							randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
							}	
				
				//--> CREDIT VS. SOCIAL

						foreach v in `var_longlist' {
							randcmd((treat_credit) reg `v' treat_credit x1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
							}	
		
			
				//--> WESTFALL YOUNG OMIBUS TEST
	
					#delimit ;
						randcmd ((treat_credit treat_sm) reg age treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg female treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg marital_status treat_credit treat_sm, cluster(fu_feb05))
						((treat_credit treat_sm) reg head_hh treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg education treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg consumption_hh treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg work_month treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg nfirst_job treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg work_vb treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg weighted_num_co_alive treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg still_work_nrsp_2years treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg overtime_perday treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg credit_bonus treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg soc_help_credit treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg volunteer_before_nrsp treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg job_like_help treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg weighted_num_active_loan treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg inv_ratio_miss_pay_20 treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg weighted_num_new_loan treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg weighted_amount_issue treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg inv_ratio_miss_pay_month treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg wmiss_pay_maturity_month treat_credit treat_sm, cluster(fu_feb05))
						((treat_sm) reg age treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg female treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg marital_status treat_sm if treat==1, cluster(fu_feb05))
						((treat_sm) reg head_hh treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg education treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg consumption_hh treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg work_month treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg nfirst_job treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg work_vb treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg weighted_num_co_alive treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg still_work_nrsp_2years treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg overtime_perday treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg credit_bonus treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg soc_help_credit treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg volunteer_before_nrsp treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg job_like_help treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg weighted_num_active_loan treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg inv_ratio_miss_pay_20 treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg weighted_num_new_loan treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg weighted_amount_issue treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg inv_ratio_miss_pay_month treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg wmiss_pay_maturity_month treat_sm if treat==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed'); 
				
					#delimit cr
				
				restore	
		log close			
		
	*********************************************************************************************************************************************************

	
	
//--> OUTPUT: ONLINE APPENDIX TABLE D.6 (BAANCE TEST, SO EVAL RESTRICTED SAMPLE)
	*********************************************************************************************************************************************************
	
	
		//--> SELECTION IN FOLLOWUP SURVEY
			
				preserve
				use "$data/eval_fa_vars.dta", clear
				keep fw_code eval_so
				sort fw_code
				tempfile temp_eval_so
				save `temp_eval_so'
				restore
				
				sort fw_code
				merge fw_code using `temp_eval_so'
				drop _m
		
		
		//--> KEEP FOLLOWUP SAMPLE ONLY
		
				preserve
				keep if eval_so==1
				
		
		local demo_var age female marital_status head_hh education consumption_hh
		local emp_var work_month nfirst_job work_vb weighted_num_co_alive
		local pref_var still_work_nrsp_2years overtime_perday credit_bonus soc_help_credit volunteer_before_nrsp job_like_help 
		local outcome_var weighted_num_active_loan inv_ratio_miss_pay_20 weighted_num_new_loan weighted_amount_issue inv_ratio_miss_pay_month wmiss_pay_maturity_month

		local var_longlist `demo_var' `emp_var' `pref_var' `outcome_var'
		
		
		//--> COLUMNS 1-3: MEANS BY TREATMENT STATUS
			*****************************************
		
				putexcel set "$output/tableD_6 (col1-3)", replace
					putexcel A1 = "var name"
					putexcel B1 = "no bonus"
					putexcel C1 = "credit bonus"
					putexcel D1 = "social bonus"
				
				local count = 2
				foreach v in `var_longlist' {
					mean `v', over (bonus_status)
						putexcel A`count' = "`v'"
						putexcel B`count' = matrix(e(b))
					local count = `count' + 1
					}
					
					putexcel A`count' = "No. of FAs"
					putexcel B`count' = matrix(e(_N))
		


		//--> COLUMNS 4-6: RANDOMIZATION INFERENCE BASED P VALUES
			****************************************		
				
				log using "$output/tableD_6 (col4-6)", replace	
			
						
				//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL		

						foreach v in `var_longlist' {
							randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
							}	
				
				//--> CREDIT VS. SOCIAL

						foreach v in `var_longlist' {
							randcmd((treat_credit) reg `v' treat_credit x1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
							}	
		
			
				//--> WESTFALL YOUNG OMIBUS TEST
	
					#delimit ;
						randcmd ((treat_credit treat_sm) reg age treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg female treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg marital_status treat_credit treat_sm, cluster(fu_feb05))
						((treat_credit treat_sm) reg head_hh treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg education treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg consumption_hh treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg work_month treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg nfirst_job treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg work_vb treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg weighted_num_co_alive treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg still_work_nrsp_2years treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg overtime_perday treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg credit_bonus treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg soc_help_credit treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg volunteer_before_nrsp treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg job_like_help treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg weighted_num_active_loan treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg inv_ratio_miss_pay_20 treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg weighted_num_new_loan treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg weighted_amount_issue treat_credit treat_sm, cluster(fu_feb05)) ((treat_credit treat_sm) reg inv_ratio_miss_pay_month treat_credit treat_sm, cluster(fu_feb05))						
						((treat_credit treat_sm) reg wmiss_pay_maturity_month treat_credit treat_sm, cluster(fu_feb05))
						((treat_sm) reg age treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg female treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg marital_status treat_sm if treat==1, cluster(fu_feb05))
						((treat_sm) reg head_hh treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg education treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg consumption_hh treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg work_month treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg nfirst_job treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg work_vb treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg weighted_num_co_alive treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg still_work_nrsp_2years treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg overtime_perday treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg credit_bonus treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg soc_help_credit treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg volunteer_before_nrsp treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg job_like_help treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg weighted_num_active_loan treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg inv_ratio_miss_pay_20 treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg weighted_num_new_loan treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg weighted_amount_issue treat_sm if treat==1, cluster(fu_feb05)) ((treat_sm) reg inv_ratio_miss_pay_month treat_sm if treat==1, cluster(fu_feb05))						
						((treat_sm) reg wmiss_pay_maturity_month treat_sm if treat==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed'); 
				
					#delimit cr
				
				restore	
		log close			
		
	*********************************************************************************************************************************************************	
